// 增量同步工具类
class IncrementalSync {
  constructor() {
    this.lastSyncTime = new Map(); // 每个聊天的最后同步时间
    this.syncInterval = 30 * 1000; // 30秒同步一次
  }
  
  // 获取增量消息
  async getIncrementalMessages(chatId, chatType = 'single') {
    const lastSync = this.lastSyncTime.get(chatId) || 0;
    const currentTime = Date.now();
    
    try {
      // 这里需要根据实际API调整
      const response = await service({
        method: "get",
        url: chatType === 'single' 
          ? "friend_chat/getIncrementalMessages" 
          : "group_chat/getIncrementalMessages",
        params: {
          chatId: chatId,
          lastSyncTime: lastSync,
          limit: 100
        }
      });
      
      if (response.data && response.data.length > 0) {
        // 更新最后同步时间
        this.lastSyncTime.set(chatId, currentTime);
        return response.data;
      }
      
      return [];
    } catch (error) {
      console.error('增量同步失败:', error);
      return [];
    }
  }
  
  // 设置最后同步时间
  setLastSyncTime(chatId, timestamp) {
    this.lastSyncTime.set(chatId, timestamp);
  }
  
  // 获取最后同步时间
  getLastSyncTime(chatId) {
    return this.lastSyncTime.get(chatId) || 0;
  }
}

export default IncrementalSync;
